package com.ellwood.IPGuard.config;

import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springdoc.core.customizers.OpenApiCustomizer;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ProjectName: IPGuard-boot
 * @PackageName: com.ellwood.IPGuard.config
 * @ClassName: WebFluxKnife4jConfig
 * @Description: // Knife4j 配置
 * @Author: Ellwood
 * @CreateDate: 2024/9/25 - 上午11:43
 * @Version: V1.0.0
 */
@Configuration
public class WebFluxKnife4jConfig {

    @Bean
    public GroupedOpenApi ellwoodOpenApi(@Value("${springdoc.version}") String appVersion){
            String[] paths = {"/api/sys/**"};
            String[] packagedToMatch = {"com.ellwood.IPGuard.controller.system"};
        return GroupedOpenApi
                .builder()
                .group("Ell系统管理")
                .addOpenApiCustomizer(openApiCustomizerEllwood(appVersion))
                .pathsToMatch(paths)
                .packagesToScan(packagedToMatch)
                .build();
    }


    private OpenApiCustomizer openApiCustomizerEllwood(String appVersion)
    {
        return openApi -> openApi.info(
                new Info()
                        .title("Ellwood 接口文档")
                        .description("ellwood 后台管理API接口")
                        .contact(
                                new Contact()
                                        .name("Ellwood")
                                        .email("ellwood-pro@qq.com")
                                        .url("http://192.168.31.161:8088/doc.html")
                        )
                        .version(appVersion)
                        .license(
                                new License()
                                        .name("Apache 2.0")
                                        .url("https://springdoc.org")
                        )
        );
    }

    @Bean
    public GroupedOpenApi softOpenApi(@Value("${springdoc.version}") String appVersion) {
            String[] paths = {"/api/soft/**"};
        String[] packagedToMatch = {"com.ellwood.IPGuard.controller.soft"};
        return GroupedOpenApi.builder().group("软装撰写管理")
                .addOpenApiCustomizer(openApiCustomizerSoft(appVersion))
                .pathsToMatch(paths)
                .packagesToScan(packagedToMatch)
                .build();
    }

    private OpenApiCustomizer openApiCustomizerSoft(String appVersion){
        return openApi -> openApi.info(
                new Info()
                        .title("软装撰写 接口文档")
                        .description("软装撰写 后台管理API接口")
                        .contact(
                                new Contact()
                                        .name("ellwood")
                                        .email("ellwood-pro@qq.com")
                                        .url("http://192.168.31.161:8088/doc.html")
                        )
                        .version(appVersion)
                        .license(
                                new License()
                                        .name("Apache 2.0")
                                        .url("http://springdoc.org")
                        )
        );
    }

}
